package com.nbsaas.boot.sql;

import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statement;

public class SqlValidator {
    public static boolean isValidSQL(String sql) {
        try {
            CCJSqlParserUtil.parse(sql);
            return true; // 语法正确
        } catch (Exception e) {
            return false; // 语法错误
        }
    }

    public static void main(String[] args) {
        String sql1 = "SELECT id, name FROM users WHERE age > 20";
        String sql2 = "SELEC id FROM";  // 故意写错

        System.out.println("SQL1 是否正确: " + isValidSQL(sql1));
        System.out.println("SQL2 是否正确: " + isValidSQL(sql2));
    }
}
